package beautiful.butterfly.drds.schedule.task;

import org.apache.zookeeper.data.Stat;

import java.util.List;
import java.util.Map;


/**
 * �����������Ŀͻ��˽ӿڣ������л������ݿ��ʵ�֣������л���ConfigServer��ʵ��
 *
 * @author xuannan
 */
public interface IDataManager {
    public long getSystemTime();

    /**
     * ����װ�ص�ǰserver��Ҫ��������ݶ���
     *
     * @param taskType ��������
     * @param uuid     ��ǰserver��UUID
     * @return
     * @throws Exception
     */
    public List<beautiful.butterfly.drds.schedule.TaskItem> reloadDealTaskItem(String taskType, String uuid) throws Exception;

    /**
     * װ�����е����������Ϣ
     *
     * @param taskType
     * @return
     * @throws Exception
     */
    public List<TaskItem> loadAllTaskItem(String taskType) throws Exception;

    /**
     * �ͷ��Լ��ѳ֣���������Ķ���
     *
     * @param taskType
     * @param uuid
     * @return
     * @throws Exception
     */
    public void releaseDealTaskItem(String taskType, String uuid) throws Exception;

    /**
     * ��ȡһ���������͵Ĵ����������
     *
     * @param taskType
     * @return
     * @throws Exception
     */
    public int queryTaskItemCount(String taskType) throws Exception;

    /**
     * װ���������������Ϣ
     *
     * @param taskType
     * @throws Exception
     */
    public TaskType loadTaskTypeBaseInfo(String taskType) throws Exception;

    /**
     * ����Ѿ����ڵĵ��ȷ�������Ϣ
     *
     * @param taskInfo
     * @throws Exception
     */
    public int clearExpireScheduleServer(String taskType, long expireTime) throws Exception;

    /**
     * ���������Ϣ���������Ѿ������ڵ�ʱ��
     *
     * @param taskInfo
     * @throws Exception
     */
    public int clearTaskItem(String taskType, List<String> serverList) throws Exception;

    /**
     * ��ȡ���е���Ч��������Ϣ
     *
     * @param taskInfo
     * @return
     * @throws Exception
     */
    public List<Server> selectAllValidScheduleServer(String taskType) throws Exception;

    public List<String> loadScheduleServerNames(String taskType) throws Exception;

    /**
     * ���·�������Item
     *
     * @param taskType
     * @param serverList
     * @throws Exception
     */
    public void assignTaskItem(String taskType, String currentUuid, int maxNumOfOneServer, List<String> serverList) throws Exception;

    /**
     * ����������Ϣ
     *
     * @param server
     * @throws Exception
     */
    public boolean refreshScheduleServer(Server server) throws Exception;

    /**
     * ע�������
     *
     * @param server
     * @throws Exception
     */
    public void registerScheduleServer(Server server) throws Exception;

    /**
     * ע��������
     *
     * @param serverUUID
     * @throws Exception
     */
    public void unRegisterScheduleServer(String taskType, String serverUUID) throws Exception;

    /**
     * ����Ѿ����ڵ�OWN_SIGN���Զ����ɵ�����
     *
     * @param taskType           ��������
     * @param serverUUID         ������
     * @param expireDateInternal ����ʱ�䣬����Ϊ��λ
     * @throws Exception
     */
    public void clearExpireTaskTypeRunningInfo(String baseTaskType, String serverUUID, double expireDateInternal) throws Exception;

    public boolean isLeader(String uuid, List<String> serverList);

    public void pauseAllServer(String baseTaskType) throws Exception;

    public void resumeAllServer(String baseTaskType) throws Exception;

    public List<TaskType> getAllTaskTypeBaseInfo() throws Exception;

    /**
     * ���һ���������͵���������Ϣ
     *
     * @param baseTaskType
     * @throws Exception
     */
    public void clearTaskType(String baseTaskType) throws Exception;

    /**
     * ����һ���µ���������
     *
     * @param baseTaskType
     * @throws Exception
     */
    public void createBaseTaskType(TaskType baseTaskType) throws Exception;

    public void updateBaseTaskType(TaskType baseTaskType) throws Exception;

    public List<TaskTypeRunningInfo> getAllTaskTypeRunningInfo(String baseTaskType) throws Exception;

    /**
     * ɾ��һ����������
     *
     * @param baseTaskType
     * @throws Exception
     */
    public void deleteTaskType(String baseTaskType) throws Exception;

    /**
     * ����������ѯ��ǰ���ȷ���
     *
     * @param baseTaskType
     * @param ownSign
     * @param ip
     * @param orderStr
     * @return
     * @throws Exception
     */
    public List<Server> selectScheduleServer(String baseTaskType, String ownSign, String ip, String orderStr)
            throws Exception;

    /**
     * ��ѯ���ȷ������ʷ��¼
     *
     * @param baseTaskType
     * @param ownSign
     * @param ip
     * @param orderStr
     * @return
     * @throws Exception
     */
    public List<Server> selectHistoryScheduleServer(String baseTaskType, String ownSign, String ip, String orderStr)
            throws Exception;

    public List<Server> selectScheduleServerByManagerFactoryUUID(String factoryUUID) throws Exception;

    /**
     * ���������ע�����е� CurrentSever��RequestServer����������
     *
     * @param taskItems
     * @throws Exception
     */
    public void createScheduleTaskItem(TaskItem[] taskItems) throws Exception;

    /**
     * ���������״̬�ʹ�����Ϣ
     *
     * @param taskType
     * @param sts
     * @param message
     */
    public void updateScheduleTaskItemStatus(String taskType, String taskItem, TaskItemStatus sts, String message) throws Exception;

    /**
     * ɾ��������
     *
     * @param taskType
     * @param taskItem
     */
    public void deleteScheduleTaskItem(String taskType, String taskItem) throws Exception;

    /**
     * ��ʼ��������ȵ�����Ϣ�;�̬������Ϣ
     *
     * @param baseTaskType
     * @param ownSign
     * @param serverUUID
     * @throws Exception
     */
    public void initialRunningInfo4Static(String baseTaskType, String ownSign, String uuid) throws Exception;

    public void initialRunningInfo4Dynamic(String baseTaskType, String ownSign) throws Exception;

    /**
     * ��������Ϣ�Ƿ��ʼ���ɹ�
     *
     * @param baseTaskType
     * @param ownSign
     * @param serverUUID
     * @return
     * @throws Exception
     */
    public boolean isInitialRunningInfoSucuss(String baseTaskType, String ownSign) throws Exception;

    public void setInitialRunningInfoSucuss(String baseTaskType, String taskType, String uuid) throws Exception;

    public String getLeader(List<String> serverList);

    public long updateReloadTaskItemFlag(String taskType) throws Exception;

    public long getReloadTaskItemFlag(String taskType) throws Exception;

    /**
     * ͨ��taskType��ȡ��ǰ���е�serverList��Ϣ��
     *
     * @param taskType
     * @return
     * @throws Exception
     */
    public Map<String, Stat> getCurrentServerStatList(String taskType) throws Exception;

}
